$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'mercharReport/useradvance/list',
        datatype: "json",
        colModel: [
            {label: '会员名', name: 'name', index: 'name', width: 80},
            {label: '交易时间', name: 'mtime', index: 'mtime', width: 80},
            {label: '业务摘要', name: 'memo', index: 'memo', width: 80},
            {label: '存入金额', name: 'importMoney', index: 'import_money', width: 80},
            {label: '支出金额', name: 'explodeMoney', index: 'explode_money', width: 80},
            {label: '当前余额', name: 'memberAdvance', index: 'member_advance', width: 80},
            {label: '支付方式', name: 'paymethod', index: 'paymethod', width: 80},
            {label: '支付单号', name: 'paymentId', index: 'payment_id', width: 80},
            {label: '订单号', name: 'orderId', index: 'order_id', width: 80},
            {label: '管理备注', name: 'message', index: 'message', width: 80}
        ],
        viewrecords: true,
        height: window.innerHeight-125,
        rowNum: 25,
        rowList: [25, 50, 80],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: false,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount",
            userdata: "userData"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
            vm.advancePaymentEnum = $("#jqGrid").jqGrid('getGridParam', 'userData').advancePaymentEnum;
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        userAdvance: {},
        advancePaymentEnum:[],
        q: {
            name: '',
            paymethod:'',
            beginCreatetime: '',
            endCreatetime: ''
        }
    },
    methods: {
        checkBeginDate: function () {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd HH:mm:ss', isShowClear: false, onpicking: function (dp) {
                    vm.q.beginCreatetime = dp.cal.getNewDateStr();
                }
            })
        },
        checkEndDate: function () {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd HH:mm:ss', isShowClear: false, onpicking: function (dp) {
                    vm.q.endCreatetime = dp.cal.getNewDateStr();
                }
            })
        },
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.userAdvance = {};
        },
        update: function (event) {
            var logId = getSelectedRow();
            if (logId == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(logId)
        },
        saveOrUpdate: function (event) {
            var url = vm.userAdvance.logId == null ? "mercharReport/useradvance/save" : "mercharReport/useradvance/update";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.userAdvance),
                success: function (r) {
                    if (r.code === 0) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        del: function (event) {
            var logIds = getSelectedRows();
            if (logIds == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                $.ajax({
                    type: "POST",
                    url: baseURL + "mercharReport/useradvance/delete",
                    contentType: "application/json",
                    data: JSON.stringify(logIds),
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功', function (index) {
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        getInfo: function (logId) {
            $.get(baseURL + "mercharReport/useradvance/info/" + logId, function (r) {
                vm.userAdvance = r.userAdvance;
            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {//postData此数组内容直接赋值到url上，参数类型：{name1:value1…}
                    'name': vm.q.name.trim(),
                    'paymethod':vm.q.paymethod,
                    'beginCreatetime': vm.q.beginCreatetime,
                    'endCreatetime': vm.q.endCreatetime,
                },
                page: 1
            }).trigger("reloadGrid");
        },
        reset() {
            vm.q.name = '';
            vm.q.paymethod = '';
            vm.q.beginCreatetime = '';
            vm.q.endCreatetime = '';
            vm.reload();
        },
        exportExcel() {
            //导出excel
            vm.q.name = vm.q.name.trim()
            //encodeURIComponent()编译url中的参数
            const data = encodeURIComponent(JSON.stringify(vm.q));
            window.location.href = baseURL + "mercharReport/useradvance/exportExcel?postData=" + data;
        }
    }
});